package com.thread.laoma;

/**
 * @author zhuangqi
 * @@date 2017/3/27.
 */
public class WaitThread extends Thread{

    private volatile boolean fire = false;

    @Override
    public void run() {
        try {
            synchronized (this){
                while (!fire){
                    wait();
                }
            }
            System.out.println("fire in thread ...");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public synchronized void fire() {
        this.fire = true;
        notify();
    }

    public static void main(String[] args) throws InterruptedException {
        WaitThread waitThread = new WaitThread();
        waitThread.start();
        Thread.sleep(6000);
        System.out.println("fire");
        waitThread.fire();
    }
}
